/*
 * Properties.c
 *
 *  Created on: 2011-7-6
 *      Author: gexiao
 */
#include "Dalvik.h"

#include <stdlib.h>
#include <sys/utsname.h>
#include <limits.h>
#include <unistd.h>

/*
 * Create some storage for properties read from the command line.
 */bool dvmPropertiesStartup(int maxProps) {
	gDvm.maxProps = maxProps;
	if (maxProps > 0) {
		gDvm.propList = (char**) malloc(maxProps * sizeof(char*));
		if (gDvm.propList == NULL)
			return false;
	}
	gDvm.numProps = 0;
	return true;
}

/*
 * Clean up.
 */
void dvmPropertiesShutdown(void) {
	int i;

	for (i = 0; i < gDvm.numProps; i++)
		free(gDvm.propList[i]);
	free(gDvm.propList);
	gDvm.propList = NULL;
}

/*
 * Add a property specified on the command line.  "argStr" has the form
 * "name=value".  "name" must have nonzero length.
 *
 * Returns "true" if argStr appears valid.
 */
bool dvmAddCommandLineProperty(const char* argStr) {
	char* mangle;
	char* equals;

	mangle = strdup(argStr);
	equals = strchr(mangle, '=');
	if (equals == NULL || equals == mangle) {
		free(mangle);
		return false;
	}
	*equals = '\0';

	assert(gDvm.numProps < gDvm.maxProps);
	gDvm.propList[gDvm.numProps++] = mangle;

	return true;
}
